package com.sxfans.encryp.utils;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
public class Base64Coder {
	public final static String ENCODING = "UTF-8";
	
	public static String base64Encode(String data,boolean rfc) throws IOException
	{
		return base64Encode(data.getBytes(ENCODING),rfc);
	}
	
	public static String base64Encode(byte[] data,boolean rfc) throws IOException
	{
		byte[] b = Base64.encodeBase64(data,rfc);
		return new String(b,ENCODING);
	}
	
	public static String base64EncodeSafe(byte[] data) throws IOException
	{
		return base64Encode(data,true);
	}
	
	public static String base64EncodeSafe(String data) throws IOException
	{
		return base64Encode(data,true);
	}
	
	public static String UrlBase64Encode(String data) throws IOException
	{
		byte[] b =Base64.encodeBase64URLSafe(data.getBytes("UTF-8"));
		return new String(b,ENCODING);
	}
	
	public static String decode(String data) throws IOException
	{
		byte[] b =Base64.decodeBase64(data.getBytes(ENCODING));
		return new String(b,ENCODING);
	}
	
	public static void main(String[] args) throws IOException {
		String str = "中华人民共和国北京市朝阳区朝外大街甲六万通中心10层";
		String msg = base64Encode(str,false);
		System.out.println(msg);
		String str2 = decode(msg);
		System.out.println(str2);
		
		System.out.println(Base64Coder.decode("/v+TgRpB4qSKIeDUp4E6LA=="));
	}
}
